
var initScreen=function(callback){//初始化html  font-size
    $("html").css("font-size",document.documentElement.clientHeight/document.documentElement.clientWidth<1.5 ? (document.documentElement.clientHeight/603*312.5+"%") : (document.documentElement.clientWidth/375*312.5+"%")); //单屏全屏布局时使用,短屏下自动缩放
    //$("html").css("font-size",document.documentElement.clientWidth/375*312.5+"%");//长页面时使用,不缩放
    if(callback)callback();
};
var app = {
    init : function(){
        var _ts = this;
        _ts.load.init();
        _ts.resize.init();
        //_ts.swiper.init();
        _ts.page2.init();
        _ts.page3.init();
        _ts.page5.init();
    },
    //load
    load : {
        init : function(){
            var _ts = this;
            _ts.run();
        },
        run : function(){
            //load
            var loader = new PxLoader();
            var imgs = [];
            var imgArr = ["click-btn.png","nextPage.png","page1-bg.png","page1-logo.png","page1-n1.png","page1-n2.png","page1-n3.png","page1-n4.png","page1-n5.png","page2-bg.png","page2-bigTk.png","page2-boom1.png","page2-boom2.png","page2-boom3.png","page2-boom4.png","page2-cannonCen.png","page2-cannonLeft.png","page2-cannonRight.png","page2-end.jpg","page2-smallTk1.png","page2-smallTk2.png","page2-smallTk3.png","page2-smallTk4.png","page2-zd.png","page3-bg.png","page3-goddess.png","page3-n1.png","page3-n2.png","page3-n3.png","page3-n4.png","page3-n5.png","page3-tit.png","page4-avatar1.png","page4-avatar2.png","page4-avatar3.png","page4-avatar4.png","page4-avatar5.png","page4-avatar6.png","page4-bg.png","page4-n1.png","page4-n2.png","page4-n3.png","page4-n4.png","page4-n5.png","page4-n6.png","page5-bg.png","page5-n1.png","page5-n2.png","page5-n3.png","page5-n4.png","page5-n5.png","page5-n6.png","page5-n7.png","page5-n8.png","page5-n9.png"];
            console.log(imgArr);
            for(var i = 0;i < imgArr.length;i++){
                imgs[i] = 'images/'+ imgArr[i] +'';
            }

            var pxImg = new PxLoaderImage(imgs[i]);
            loader.add(pxImg);
            
            loader.addProgressListener(function(e) {
                console.log(e)
            });

            loader.addCompletionListener(function(e) {
                var i = 0;
                var loadSet = setInterval(function(){
                        i++;
                        if(i > 100){
                            $(".loading").hide();
                            clearInterval(loadSet);
                            app.swiper.init();
                        }else{
                            $(".load-txt").html(i+"%");
                        }
                    },50);
            });

            loader.start();
        } 
    },
    //屏幕尺寸改变重置
    resize : {
        init : function(){
            var _ts = this;
            _ts.run();
        },
        run : function(){
            window.addEventListener("orientationchange" in window ? "orientationchange" : "resize",function(e){
                var st=setTimeout(initScreen,300);
            }, false);
        }
    },
    swiper : {
        init : function(){
            var _ts = this;
            _ts.run();
        },
        run : function(){
            var mySwiperV = new Swiper ('.swiper-container-v', {
                direction: 'vertical',
                observer:true,
                autoplayDisableOnInteraction: false,
                mousewheelControl : true,
                noSwiping : true,
                noSwipingClass : 'stop-swiping',
                onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
                    swiperAnimateCache(swiper); //隐藏动画元素 
                    swiperAnimate(swiper); //初始化完成开始动画
                },
                onSlideChangeEnd: function(swiper){ 
                    swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
                }
            });
            //mySwiperV.slideTo(4, 10, false);//切换到第一个slide，速度为1秒
        }
    },
    page2 : {
        init : function(){
            var _ts = this;
            _ts.run();
        },
        run : function(){
            $(".click-btn").on("touchstart",function(){
                $(this).hide(1000);
                $(".page2-tip").hide(1000);
                //子弹
                setTimeout(function(){
                    /*$(".smallTk .flex").eq(0).addClass("hzl");*/
                    $(".sm").eq(0).addClass("hzl");
                    $(".smallTk1").addClass("zd");
                },1000);
                setTimeout(function(){
                    $(".sm").eq(1).addClass("hzl");
                    $(".smallTk2").addClass("zd");
                },2000);
                setTimeout(function(){
                    $(".sm").eq(2).addClass("hzl");
                    $(".smallTk3").addClass("zd");
                },3000);
                setTimeout(function(){
                    $(".sm").eq(3).addClass("hzl");
                    $(".smallTk4").addClass("zd");
                },4000);
                //爆炸
                setTimeout(function(){
                    $(".boom-n1").addClass("boom");
                },1500);
                setTimeout(function(){
                    $(".boom-n2").addClass("boom");
                },2500);
                setTimeout(function(){
                    $(".boom-n3").addClass("boom");
                },3500);
                setTimeout(function(){
                    $(".boom-n4").addClass("boom");
                },4500);
                setTimeout(function(){
                    $(".page2-end").show().addClass("zoomIn animated");
                },5000);
            })
        }
    },
    //第三屏
    page3 : {
        init : function(){
            var _ts = this;
            _ts.run();
        },
        run : function(){
            var mp3 = $("#mp3")[0];
            var mp3_time;
            var is = true;
            $("#mp3").on("canplay",function(){
                mp3_time = mp3.duration;
                //console.log(mp3_time);
                $(".audio-box .time").text(parseInt(mp3_time));
            })
            $(".audio-box").on("touchstart",function(){
                
                if(is){
                    is = false;
                    $(".play").hide();
                    mp3.play();
                    var setTime = setInterval(function(){
                        mp3_time--;
                        if(mp3_time <= 0){
                            mp3_time = mp3.duration;
                            clearInterval(setTime);
                            $(".play").show();
                            is = true;
                        }
                        $(".audio-box .time").text(parseInt(mp3_time));
                    },1000)
                }
            })
        }
    },
    //第五屏
    page5 : {
        init : function(){
            var _ts = this;
            _ts.run();
        },
        run : function(){
            //长按指纹时
            $(".touch").on("touchstart",function(e){
                e.preventDefault();
                $(this).find(".touch-btn").removeClass("zw");
                $(".line").addClass("line-re");
                $(".touch-alp").addClass("touch-re")
            });
            //取消长按时
            $(".touch").on("touchend",function(e){
                e.preventDefault();
                $(this).find(".touch-btn").addClass("zw");
                $(".line").removeClass("line-re");
                $(".touch-alp").removeClass("touch-re")
            });
            $(".line").on("webkitAnimationEnd", function(e) {//动画执行完做什么
                e.preventDefault();
                alert("功能暂没完善");
            });
        }
    }
}

$(function(){
    initScreen(function(){
        //调用
        app.init();
        }
    );
})